<template>
  <div>
    <el-tabs @tab-click="handleClick" active-name="1">
      <el-tab-pane label="基本属性" name="1">
        <div style="width: 400px">
          <el-form :model="ptp" ref="ptp" label-width="100px" class="config_form">
            <div>
              <el-form-item label="名称">
                <el-input v-model="ptp.name" readonly></el-input>
              </el-form-item>
              <el-form-item label="工作状态">
                <el-input v-model="ptp.statePac.operationalState" readonly></el-input>
              </el-form-item>
              <el-form-item label="接口类型">
                <el-input v-model="ptp['interface-type']" readonly></el-input>
              </el-form-item>
            </div>

            <el-form-item label="管理状态" pprop="statePac.adminState" style="margin-top: 3px">
              <el-select v-model="ptp.statePac.adminState">
                <el-option value="使能"></el-option>
                <el-option value="禁止"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="激光器状态" prop="mac-address">
              <el-select v-model="ptp['laser-status']">
                <el-option value="使能"></el-option>
                <el-option value="禁止"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="环回类型">
              <el-select v-model="ptp['loop-back']">
                <el-option value="内环回"></el-option>
                <el-option value="外环回"></el-option>
                <el-option value="无环回"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="协议类型">
              <el-select v-model="ptp['layer-protocol-name']">
                <el-option value="ETH"></el-option>
                <el-option value="SDH"></el-option>
                <el-option value="ODU"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')" style="float: right">确定</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-tab-pane>

      <el-tab-pane :label="title" name="2">
        <div>
          <div v-show="isEth">
            <EthPtp/>
          </div>
          <div v-show="isOdu">
            <OduPtp/>
          </div>
          <div v-show="isSdh">
            <SdhPtp/>
          </div>
        </div>
      </el-tab-pane>

      <div v-show="false">
        <el-tab-pane label="ETH" name="2">
          <EthPtp/>
        </el-tab-pane>

        <el-tab-pane label="ODU" name="3">
          <OduPtp/>
        </el-tab-pane>
        <el-tab-pane label="SDH" name="4">
          <SdhPtp/>
        </el-tab-pane>
      </div>
    </el-tabs>
  </div>

</template>

<script>
import axios from "axios";
import EthPtp from "@/components/dispose/ptp/EthPtp";
import OduPtp from "@/components/dispose/ptp/OduPtp";
import SdhPtp from "@/components/dispose/ptp/SdhPtp";

export default {
  name: "Ptp",
  components: {
    EthPtp,
    OduPtp,
    SdhPtp
  },
  data() {
    return {
      nodeName: '',
      title:'',

      isEth: false,
      isOdu: false,
      isSdh: false,

      ptp: {
        "name": "端口1",
        "interface-type": "UNI",
        "laser-status": "禁止",
        "layer-protocol-name": "ETH",
        "loop-back": "内环回",
        statePac: {
          "adminState": "使能",
          "operationalState": 'down',
        },
      }
    }
  },
  methods: {
    isTabs(protocol) {
      switch (protocol) {
        case 'ETH':
          this.isEth = true;
          this.isOdu = false;
          this.isSdh = false;
          break;
        case 'ODU':
          this.isEth = false;
          this.isOdu = true;
          this.isSdh = false;
          break;
        case 'SDH':
          this.isEth = false;
          this.isOdu = false;
          this.isSdh = true;
          break;
        default:
          this.isEth = false;
          this.isOdu = false;
          this.isSdh = false;
          break;
      }
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    getPtps() {
      axios.get("/node/" + this.nodeName + "/ptps").then(
          response => {
            console.log("请求成功", response.data);
            this.ptps = response.data;
            // response.data;
          },
          error => {
            console.log("失败！", error.message)
          }
      )
    },
    submitForm(formName) {
      console.log(formName)
    }
  },
  mounted() {
    this.ptp.name = this.$route.params.name;
    this.title = this.$route.params.protocol;
    console.log('XIEYI',this.$route.params.protocol);
    this.isTabs(this.$route.params.protocol);
    this.$bus.$on('node-name', (data) => {
      console.log('PTP - node : ', data);
      this.nodeName = data;
    })
    this.$bus.$on('ptp-name', (data) => {
      console.log('ptp基本信息收到了消息', data)
      this.ptp.name = data;
    })
  }
}
</script>

<style scoped>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>